//# 游戏管理器脚本

using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public static GameManager Instance { get; private set; }
    public Nezha player;
    
    [Header("UI")]
    public Slider healthBar;
    public Text scoreText;
    private int score = 0;

    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    void Update()
    {
        if (player != null && healthBar != null)
        {
            healthBar.value = player.currentHealth / player.maxHealth;
            if (player.currentHealth <= 0)
            {
                EndGame();
            }
        }
    }

    public void EndGame()
    {
        // 游戏结束逻辑
        Debug.Log("Game Over!");
        // 可以添加更多的游戏结束处理逻辑，例如显示重启按钮
    }

    public void AddScore(int points)
    {
        score += points;
        if (scoreText != null)
        {
            scoreText.text = "Score: " + score;
        }
    }

    public void RestartGame()
    {
        // 重启游戏逻辑
        UnityEngine.SceneManagement.SceneManager.LoadScene(
            UnityEngine.SceneManagement.SceneManager.GetActiveScene().name
        );
    }
}